package com.example.substation.common;

import java.util.HashMap;

public class FrameResponse extends HashMap<String, Object> {

    private static final long serialVersionUID = 6769157532172136264L;

    private static final int CODE = 200;

    private static final long COUNT = 0L;

    private FrameResponse() {}

    public FrameResponse(int code, String message, Long count, Object data) {
        this.put("status", true);
        this.put("code", code);
        this.put("message", message);
        this.put("count", count);
        this.put("data", data);
    }

    /*
     * 重写put 并且返回自身实现链式
     */
    @Override
    public FrameResponse put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    /*
     * del 删除某个键 并且返回自身实现链式
     */
    public FrameResponse del(String key) {
        super.remove(key);
        return this;
    }

    public static FrameResponse success() {
        return new FrameResponse(CODE, "", COUNT, null);
    }

    public static FrameResponse success(Object data) {
        return new FrameResponse(CODE, "", COUNT, data);
    }

    public static FrameResponse success(Object data, Long count) {
        return new FrameResponse(CODE, "", count, data);
    }

    public static FrameResponse success(int code, Object data) {
        return new FrameResponse(code, "", COUNT, data);
    }

    public static FrameResponse failure(String message) {
        return new FrameResponse(90000, message, COUNT, null);
    }

    public static FrameResponse failure(int code, String message) {
        return new FrameResponse(code, message, COUNT, null);
    }

    public static FrameResponse failure(int code, String message, Object data) {
        return new FrameResponse(code, message, COUNT, data);
    }
}
